Skip to content

Conversation

@bayrem-gharsellaoui
Copy link

@bayrem-gharsellaoui bayrem-gharsellaoui commented Jun 5, 2024

This commit Adds the ability for the user to register a callback for Serial/SerialUSB events (TX/RX)

Pull Request template

Please, Make sure that your PR is not a duplicate.
Search among the Pull request before creating one.

IMPORTANT: Please review the CONTRIBUTING.md file for detailed contributing guidelines.

Thanks for submitting a pull request.
Please provide enough information so that others can review your pull request:

Summary

This PR fixes/implements the following bugs/features

  • Add Serial events callback

Explain the motivation for making this change. What existing problem does the pull request solve?

#include <Arduino.h>

#define SERIAL_BAUDRATE 115200U

static uint32_t count = 0;

static void onSerialEvent(SerialEvent_t event);

void setup() {
  Serial.begin(SERIAL_BAUDRATE);
  Serial.onEvent(onSerialEvent);
}

void loop() {
  Serial.print("Running(");
  Serial.print(count);
  Serial.println(")...");
  count++;
  delay(1000);
}

static void onSerialEvent(SerialEvent_t event) {
  switch (event) {
    case SERIAL_EVENT_RX:
      __NOP();
      break;
    case SERIAL_EVENT_TX:
      __NOP();
      break;
    default:
      __NOP();
      break;
  }
}

Validation

  • Ensure CI build is passed.
  • Demonstrate the code is solid. [e.g. Provide a sketch]

Code formatting

  • Ensure AStyle check is passed thanks CI

Closing issues

Fixes #xxx

This commit Adds the ability for the user to register a callback for Serial/SerialUSB events (TX/RX)

Signed-off-by: kaizoku-oh <garssallaoui.bayrem@gmail.com>
@fpistm
Copy link
Member

fpistm commented Jun 6, 2024

Hi @kaizoku-oh
First thanks for the PR.
I don't understand why add an event on TX, as application known when it transmit.
About Rx, Arduino already specified an API for this (even if it only processes each loop):
https://www.arduino.cc/reference/en/language/functions/communication/serial/serialevent/
considered deprecated in favor of available().

So I wonder if having this kind of change is really a good idea. Or the Arduino Core API should be updated by requesting this new API:
https://github.com/arduino/ArduinoCore-API/issues

@fpistm fpistm marked this pull request as draft June 11, 2024 15:21
@fpistm
Copy link
Member

fpistm commented Jun 14, 2024

Close it as no feedback from OP.

@fpistm fpistm closed this Jun 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants